package com.baixun.gassystem.mapper;

import com.baixun.gasentity.entity.SysDepartmentRoles;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 系统部门角色映射器接口
 * 继承自BaseMapper，用于对系统部门角色相关数据库操作进行映射
 */
@Mapper
public interface SysDepartmentRolesMapper extends BaseMapper<SysDepartmentRoles> {

    @Select("SELECT r.id FROM sys_department_user_roles ur " +
            "JOIN sys_department_roles r ON ur.role_id = r.id " +
            "WHERE ur.user_id = #{userId}")
    List<Long> findRoleIdsByUserId(@Param("userId") Long userId);

    @Delete("DELETE FROM sys_role_permissions WHERE role_id = #{roleId}")
    void deleteRolePermissions(@Param("roleId") Long roleId);

    @Insert("INSERT INTO sys_role_permissions (role_id, permission_id) VALUES (#{roleId}, #{permissionId})")
    void insertRolePermission(@Param("roleId") Long roleId, @Param("permissionId") Long permissionId);
}

